<html>
<head><meta charset="utf-8"><title>Request: slice::from_raw_parts · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html">Request: slice::from_raw_parts</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="196031848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196031848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196031848">(May 02 2020 at 04:07)</a>:</h4>
<p>Are there any current blockers to making <code>slice::from_raw_parts</code> (and the mut verison) into a const fn?</p>



<a name="196036306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196036306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196036306">(May 02 2020 at 06:14)</a>:</h4>
<p>stabilizing it as const fn is blocked on allowing <code>transmute</code> or <code>union</code> field accesses in const fn</p>



<a name="196036311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196036311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196036311">(May 02 2020 at 06:14)</a>:</h4>
<p>but you can make it const behind a feature gate I believe</p>



<a name="196066378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196066378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196066378">(May 02 2020 at 19:30)</a>:</h4>
<p>Well i think the transmute path would be UB technically i suppose, so the union field version would be the one.</p>



<a name="196066832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196066832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196066832">(May 02 2020 at 19:40)</a>:</h4>
<p>neither works outside the standard library since slice pointer memory layout is unspecified, but this function is implemented in libcore so it's fine either way</p>



<a name="196068196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196068196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196068196">(May 02 2020 at 20:12)</a>:</h4>
<p>I'm aware. I meant even within libcore.</p>



<a name="196068862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196068862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196068862">(May 02 2020 at 20:30)</a>:</h4>
<p>Why would the transmute be UB in libcore? It's libcore, it can do whatever it wants.</p>



<a name="196070197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Request%3A%20slice%3A%3Afrom_raw_parts/near/196070197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Request.3A.20slice.3A.3Afrom_raw_parts.html#196070197">(May 02 2020 at 21:09)</a>:</h4>
<p>ahhhh, FatPtr&lt;T&gt; is repr(C), i forgot. nevermind me.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>